﻿using NoMiddleman.Core.DataInterfaces;
using NoMiddleman.Core.Domain;

namespace NoMiddleman.Data
{
    public class AdvertRepository : BaseRepository<Advert>, IAdvertRepository
    {
        public new Advert Get(int id)
        {
            Advert advert = base.Get(id);
            return advert;
        }

        public new Advert Save(Advert advert)
        {
            BaseRepository<Address> addressRepo = new BaseRepository<Address>();
            BaseRepository<RealEstate> realEstateRepo = new BaseRepository<RealEstate>();
            
            advert.RealEstate.Address = addressRepo.Save(advert.RealEstate.Address);
            advert.RealEstate = realEstateRepo.Save(advert.RealEstate);
            return base.Save(advert);
        }
    }
}
